package com.common.activity;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.LinearLayout;

import com.common.R;
import com.common.event.LoginOutEvent;
import com.common.event.PanelToolSelectEvent;
import com.common.utility.Logger;

import de.greenrobot.event.EventBus;

/**
 * 防ios拍照底部弹出的pannel，可以自己定义显示数量
 */
public class PanelToolActivity extends BaseActivity {

    public static final String EXTRA_PANEL_ARRAY_KEY = "panel_array_key";
    private LinearLayout mPanelContainerView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_panel_tool);
        getWindow().setLayout(LayoutParams.MATCH_PARENT,
                LayoutParams.MATCH_PARENT);
        String [] strArray = getIntent().getStringArrayExtra(EXTRA_PANEL_ARRAY_KEY);
        if(strArray == null || strArray.length == 0){
            Logger.e("datasource(String Array) is empty!!!");
            PanelToolActivity.this.finish();
        }
        mPanelContainerView = (LinearLayout)findViewById(R.id.panel_container_view);
        LayoutInflater inflater = LayoutInflater.from(this);
        for(int i = 0; i < strArray.length; i++){
            String str = strArray[i];
            Button btn = (Button)inflater.inflate(R.layout.view_panel_button_item, null);
            if(i == 0){// android:background="@drawable/"
                btn.setBackgroundResource(R.drawable.actionsheet_top_selector);
            }else if(i == strArray.length - 1){
                btn.setBackgroundResource(R.drawable.actionsheet_bottom_selector);
            }else{
                btn.setBackgroundResource(R.drawable.actionsheet_middle_selector);
            }
            btn.setId(i);
            btn.setText(str);
            btn.setOnClickListener(this);
            mPanelContainerView.addView(btn);
        }
    }

    public void onClick(View v) {
        int id = v.getId();
        if(id == R.id.btn_cancel){

        }else{
            EventBus.getDefault().post(new PanelToolSelectEvent(id));
        }
        finish();
    }

    @Override
    public void onEvent(LoginOutEvent event) {
        finish();
    }
}
